package com.atliuzu.app.func;


import com.atliuzu.utils.KeywordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.io.IOException;
import java.util.List;

/**
 * @Author : songyuan
 * @Description :
 * Date : 2022/7/26 0:37
 * @Version : 1.0
 */

@FunctionHint(output = @DataTypeHint("ROW<word string>"))
public class splitFunction extends TableFunction<Row> {

    //utdf函数 满足切词条件时，一进多出 不然，返回搜索词条
    public void eval(String keyWord) {
        try {
            List<String> list = KeywordUtil.spiltKeyWord(keyWord);
            for (String s : list) {
                collect(Row.of(s));
            }
        } catch (IOException e) {
            collect(Row.of(keyWord));
        }
    }
}
